package day_2022_9_to_12.Day;

/**
 * @author haomin
 * @date 2022/10/12 16:13
 **/
public class Day40_2_Num209_MinSubArrayLen {
    class Solution {
        public int minSubArrayLen(int target, int[] nums) {
            int minLen = 0;
            int i = 0, sum = 0;
            for(int j = 0; j < nums.length; ++j){
                sum += nums[j];
                while(sum >= target){
                    if(minLen == 0) minLen = j - i + 1;
                    else minLen = Math.min(minLen, j - i + 1);
                    sum -= nums[i++];
                }
            }
            return minLen;
        }
    }
}